package com.jpush.customer.controller;

import com.jpush.customer.feign.KeplerClient;
import com.jpush.customer.feign.ProductFeign;
import com.jpush.customer.pojo.V1CsdAppTopDetailReqDTO;
import com.jpush.customer.pojo.V1CsdNestAppCrowdCreateReqDTO;
import com.jpush.customer.service.CustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/push/customer")
public class CustomerController {

    @Autowired
    private ProductFeign productFeign;

    @Autowired
    private KeplerClient keplerClient;

    @Autowired
    private CustomerService customerService;

    private Logger log = LoggerFactory.getLogger(CustomerController.class);

    @GetMapping("/")
    public String index(){
        log.info("customer log");
        return productFeign.index();
    }

    @GetMapping("/kepler")
    public String kepler(V1CsdAppTopDetailReqDTO reqDTO, HttpServletResponse response) throws IOException {
        String index = keplerClient.index();
        return "kepler " + index;
    }
    @GetMapping("/product")
    public String product(V1CsdAppTopDetailReqDTO reqDTO, HttpServletResponse response) throws IOException {
        String index = productFeign.index();
        return "product " + index;
    }


    @GetMapping("/export")
    public void export(V1CsdAppTopDetailReqDTO reqDTO, HttpServletResponse response) throws IOException {
        customerService.export(reqDTO, response);
    }

    @PostMapping("/create-task")
    public String createTask(V1CsdNestAppCrowdCreateReqDTO reqDTO, @RequestParam(value = "file", required = false) MultipartFile file) throws IOException {
        return customerService.createTask(reqDTO, file);
    }

    @PostMapping("/multiFile")
    public String multiFile( @RequestParam(value = "photos", required = false) MultipartFile[] file) throws IOException {
        customerService.multiFile(file);
        return "multiFile";
    }
}